**********************************************************************
** 	TITLE:		Dutch legislative elections forecast - Replication	** 	
**	DATA:		dutch-forecast.dta 									**
**	AUTHORS:	dassonneville, mongrain & lewis-beck 				**
**	DATE:		may 2017 											**	
**********************************************************************


cd  "/Users/ruthdassonneville/Desktop/RP2017_ForecastingDutchElections/" 	// <-- change working directory

use "RP2017_ForecastingDutchElections.dta", clear


** DEFINE TIME SERIES DATA
	
	tsset eyear

** ESTIMATE MODEL - Table 1

	reg lpvoteshare lpvotesharet1 weightedgdp months if eyear!=2017	// exclude 2017 for model building
	estat durbina		// alternative dwatson test

** CALCULATIONS WITHIN SAMPLE FORECAST - Table 2

	gen forecast_within=0.002 + (1.175*lpvotesharet1) + (1.298*weightedgdp) + (-.146*months)

** ESTIMATING SEPARATE MODELS FOR OUT OF SAMPLE PREDICTIONS - for calculating out of sample predictions Table 3
	
	set more off
	tempname jacknife_estimates 
	drop if eyear==2017		// none of the models should include 2017
	
	postfile `jacknife_estimates' eyear e_intercept e_vote e_gdp e_months using jacknife_estimates.dta , replace

	foreach i in 1952 1956 1959 1963 1967 1971 1972 1977 1981 1982 1986 1989 1994 1998 2002 2003 2006 2010 2012 {
	reg lpvoteshare lpvotesharet1 weightedgdp months if eyear!=`i'
	post `jacknife_estimates' (`i') (`=_b[_cons]') (`=_b[lpvotesharet1]') (`=_b[weightedgdp]') (`=_b[months]') 
	}
	postclose `jacknife_estimates' 
	use jacknife_estimates , clear
	list 

** CALCULATIONS OUT OF SAMPLE FORECAST - Table 3

	use "RP2017_ForecastingDutchElections.dta", clear
	merge 1:1 eyear using "jacknife_estimates.dta"
	
	gen forecast_outofsample= e_intercept + (e_vote*lpvotesharet1) + (e_gdp*weightedgdp) + ///
	(e_months*months)
	
	
	
	
	
